$(function() {
    $("#scan-form").submit(function(event) {
      event.preventDefault();
      var target = $("#target").val();
      var ports = $("#ports").val();
      var data = {
        target: target,
        ports: ports
      };
      axios.post("/scan", data)
        .then(function(response) {
          var scanResults = response.data;
          var tableBody = $("#scan-results");
          tableBody.empty();
          for (var host in scanResults) {
            for (var proto in scanResults[host]) {
              for (var port in scanResults[host][proto]) {
                var status = scanResults[host][proto][port]["status"];
                var service = scanResults[host][proto][port]["service"];
                var version = scanResults[host][proto][port]["version"];
                tableBody.append(
                  "<tr>" +
                    "<td>" + host + "</td>" +
                    "<td>" + proto + "</td>" +
                    "<td>" + port + "</td>" +
                    "<td>" + status + "</td>" +
                    "<td>" + service + "</td>" +
                    "<td>" + version + "</td>" +
                  "</tr>"
                );
              }
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    });
  });
  